package com.shine.app.ui;

import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.RatingBar;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.assist.FailReason;
import com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener;
import com.shine.app.AppManager;
import com.shine.app.BaseActivity;
import com.shine.app.R;
import com.shine.app.bean.GolfCourseBean;
import com.shine.app.commons.StringUtils;
import com.shine.app.inject.InjectView;
import com.shine.app.inject.Injector;

public class ViewMyInfo_AddedFavoriteActivity extends BaseActivity implements
		OnClickListener {

	private GolfCourseBean golfCourseBean;
	private DisplayImageOptions options;
	@InjectView(R.id.head_back)
	private ImageView head_backImageView;

	@InjectView(R.id.progressBar)
	private ProgressBar progressBar;
	@InjectView(R.id.imageView)
	private ImageView imageView;
	@InjectView(R.id.ratingbar)
	private RatingBar ratingBar;
	@InjectView(R.id.name)
	private TextView nameTextView;
	@InjectView(R.id.address)
	private TextView addressTextView;
	@InjectView(R.id.zip)
	private TextView zipTextView;
	@InjectView(R.id.url)
	private TextView urlTextView;
	@InjectView(R.id.id)
	private TextView idTextView;
	@InjectView(R.id.submit)
	private Button submitButton;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.viewmyinfo_addedfavorite);
		Injector.get(this).inject();
		init();
	}

	private void init() {
		golfCourseBean = (GolfCourseBean) getIntent().getSerializableExtra(
				"golfCourseBean");
		options = new DisplayImageOptions.Builder()
				.showImageForEmptyUri(R.drawable.noimage)
				.showImageOnFail(R.drawable.noimage).cacheInMemory(true)
				.cacheOnDisk(true).considerExifParams(true)
				.bitmapConfig(Bitmap.Config.RGB_565).build();

		nameTextView.setText(golfCourseBean.getName());
		addressTextView.setText(golfCourseBean.getAddress1());
		zipTextView.setText(GolfCourseBean.getCityAddress(golfCourseBean));
		urlTextView.setText(golfCourseBean.getHomepage());
		ratingBar.setRating((float) golfCourseBean.getReviewAverage());
		idTextView.setTag(golfCourseBean);
		String imageUrl = golfCourseBean.getImage();
		submitButton.setOnClickListener(this);
		imageLoader.displayImage(imageUrl, imageView, options,
				new SimpleImageLoadingListener() {
					@Override
					public void onLoadingStarted(String imageUri, View view) {
						progressBar.setVisibility(View.VISIBLE);
					}

					@Override
					public void onLoadingFailed(String imageUri, View view,
							FailReason failReason) {
						progressBar.setVisibility(View.GONE);
					}

					@Override
					public void onLoadingComplete(String imageUri, View view,
							Bitmap loadedImage) {
						progressBar.setVisibility(View.GONE);
					}
				}, null);
	}

	@Override
	public void onClick(View v) {
		if (v == submitButton) {
			Intent intent = new Intent(this, ViewMyInfoFavoriteActivity.class);
			intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
			this.startActivity(intent);
			AppManager.getAppManager().finishActivity();
			overridePendingTransition(R.anim.anim, R.anim.slide_out_down);
		}
	}
}
